 /* Copyright 2018 JDCLOUD.COM

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http:#www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

oss openapi
oss openapi

OpenAPI spec version: v1
Contact: 

NOTE: This class is auto generated by the jdcloud code generator program.
*/


#import <Foundation/Foundation.h>
#import <JDCloudOCSDKOssopenapi/OssopenapiExecutor.h>

@implementation OssopenapiClient

@synthesize userAgent = _userAgent;
@synthesize serviceName = _serviceName;
@synthesize version = _version;

-(void) addCustomerHeaderWithKey:(NSString*) key
                           value:(NSString*) value{
    if(![self customHeader])
    {
        self.customHeader = [[NSMutableDictionary alloc] init];
    }
    if(key && value)
    {
        [[self customHeader] setValue:value forKey:key];
    }
   
}

-(id)initWithGlobalConfig{
    if(![GlobalConfig credential])
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@"GlobalConfig credential not config" userInfo:nil];
        @throw e;
    }
    self.credential = [GlobalConfig credential];
    if(![GlobalConfig sdkEnvironment])
    {
        self.sdkEnvironment = [[SDKEnvironment alloc] initWithEndPoint:@"ossopenapi.jdcloud-api.com"];
    }else
    {
        self.sdkEnvironment = [GlobalConfig sdkEnvironment];
    }
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 ossopenapi  v1";
    _serviceName = @"ossopenapi";
    _version = @"v1";
    self.contentType = @"application/json";
    return self;
}

-(id)initWithCredential:(Credential*)credential
         sdkEnvironment:(SDKEnvironment*)sdkEnvironment
{
    if(!credential)
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@" credential can not null" userInfo:nil];
        @throw e;
    }else{
        self.credential = credential;
    }
    
    if(!sdkEnvironment)
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@" sdkEnvironment can not null" userInfo:nil];
        @throw e;
    }else{
        self.sdkEnvironment = sdkEnvironment;
    }
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 ossopenapi  v1";
    _serviceName = @"ossopenapi";
    _version = @"v1";
    self.contentType = @"application/json";
    return self;
}

-(id)initWithCredential:(Credential*)credential
{
    if(!credential)
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@" credential can not null" userInfo:nil];
        @throw e;
    }else{
        self.credential = credential;
    }
    if(![GlobalConfig sdkEnvironment])
    {
        self.sdkEnvironment = [[SDKEnvironment alloc] initWithEndPoint:@"ossopenapi.jdcloud-api.com"];
    }else
    {
        self.sdkEnvironment = [GlobalConfig sdkEnvironment];
    }
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 ossopenapi  v1";
    _serviceName = @"ossopenapi";
    _version = @"v1";
    self.contentType = @"application/json";
    return self;
}

-(id)init{
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 ossopenapi  v1";
    _serviceName = @"ossopenapi";
    _version = @"v1";
    self.contentType = @"application/json";
    return self;
}


/**
getSingleBucketCapacity sync request
@param getSingleBucketCapacityRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `getSingleBucketCapacityResponse` the request response data model
*/
-(NSDictionary*) getSingleBucketCapacitySyncWithRequest:(OssopenapiGetSingleBucketCapacityRequest*) getSingleBucketCapacityRequest
{
OssopenapiGetSingleBucketCapacityExecutor* excutor = [[OssopenapiGetSingleBucketCapacityExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:getSingleBucketCapacityRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiGetSingleBucketCapacityResponse* response = [[OssopenapiGetSingleBucketCapacityResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"getSingleBucketCapacityResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)getSingleBucketCapacityAsyncWithRequest:(OssopenapiGetSingleBucketCapacityRequest*) getSingleBucketCapacityRequest
                       completionHandler:(void(^)(int statusCode,OssopenapiGetSingleBucketCapacityResponse* _Nullable getSingleBucketCapacityResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
OssopenapiGetSingleBucketCapacityExecutor* excutor = [[OssopenapiGetSingleBucketCapacityExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:getSingleBucketCapacityRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiGetSingleBucketCapacityResponse* response = [[OssopenapiGetSingleBucketCapacityResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
getBackSourceConfiguration sync request
@param getBackSourceConfigurationRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `getBackSourceConfigurationResponse` the request response data model
*/
-(NSDictionary*) getBackSourceConfigurationSyncWithRequest:(OssopenapiGetBackSourceConfigurationRequest*) getBackSourceConfigurationRequest
{
OssopenapiGetBackSourceConfigurationExecutor* excutor = [[OssopenapiGetBackSourceConfigurationExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:getBackSourceConfigurationRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiGetBackSourceConfigurationResponse* response = [[OssopenapiGetBackSourceConfigurationResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"getBackSourceConfigurationResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)getBackSourceConfigurationAsyncWithRequest:(OssopenapiGetBackSourceConfigurationRequest*) getBackSourceConfigurationRequest
                       completionHandler:(void(^)(int statusCode,OssopenapiGetBackSourceConfigurationResponse* _Nullable getBackSourceConfigurationResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
OssopenapiGetBackSourceConfigurationExecutor* excutor = [[OssopenapiGetBackSourceConfigurationExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:getBackSourceConfigurationRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiGetBackSourceConfigurationResponse* response = [[OssopenapiGetBackSourceConfigurationResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
putBackSourceConfiguration sync request
@param putBackSourceConfigurationRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `putBackSourceConfigurationResponse` the request response data model
*/
-(NSDictionary*) putBackSourceConfigurationSyncWithRequest:(OssopenapiPutBackSourceConfigurationRequest*) putBackSourceConfigurationRequest
{
OssopenapiPutBackSourceConfigurationExecutor* excutor = [[OssopenapiPutBackSourceConfigurationExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:putBackSourceConfigurationRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiPutBackSourceConfigurationResponse* response = [[OssopenapiPutBackSourceConfigurationResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"putBackSourceConfigurationResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)putBackSourceConfigurationAsyncWithRequest:(OssopenapiPutBackSourceConfigurationRequest*) putBackSourceConfigurationRequest
                       completionHandler:(void(^)(int statusCode,OssopenapiPutBackSourceConfigurationResponse* _Nullable putBackSourceConfigurationResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
OssopenapiPutBackSourceConfigurationExecutor* excutor = [[OssopenapiPutBackSourceConfigurationExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:putBackSourceConfigurationRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiPutBackSourceConfigurationResponse* response = [[OssopenapiPutBackSourceConfigurationResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
deleteBackSourceConfiguration sync request
@param deleteBackSourceConfigurationRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `deleteBackSourceConfigurationResponse` the request response data model
*/
-(NSDictionary*) deleteBackSourceConfigurationSyncWithRequest:(OssopenapiDeleteBackSourceConfigurationRequest*) deleteBackSourceConfigurationRequest
{
OssopenapiDeleteBackSourceConfigurationExecutor* excutor = [[OssopenapiDeleteBackSourceConfigurationExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:deleteBackSourceConfigurationRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiDeleteBackSourceConfigurationResponse* response = [[OssopenapiDeleteBackSourceConfigurationResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"deleteBackSourceConfigurationResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)deleteBackSourceConfigurationAsyncWithRequest:(OssopenapiDeleteBackSourceConfigurationRequest*) deleteBackSourceConfigurationRequest
                       completionHandler:(void(^)(int statusCode,OssopenapiDeleteBackSourceConfigurationResponse* _Nullable deleteBackSourceConfigurationResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
OssopenapiDeleteBackSourceConfigurationExecutor* excutor = [[OssopenapiDeleteBackSourceConfigurationExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:deleteBackSourceConfigurationRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    OssopenapiDeleteBackSourceConfigurationResponse* response = [[OssopenapiDeleteBackSourceConfigurationResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}


 /**
 ossopenapi common sync request
 @param  jdcloudDataRequest request param
 @return key `statusCode` http request status code type is int
             `dataResult` the http request response data  type is NSData
             `requestError` the request error type is NSError
 */
 -(NSDictionary*) ossopenapiCommonSyncWithRequest:(JDCloudDataRequest*) jdcloudDataRequest
                                                   url:(NSString*) url
                                                method:(NSString*) method{
    CommonExecutor* excutor = [[CommonExecutor alloc] initWithJDCloudClient:self url:url method:method];
    NSDictionary* responseResult = [excutor executeDataSync:jdcloudDataRequest];
    return responseResult;
}

-(void)ossopenapiCommonAsyncWithRequest:(JDCloudDataRequest*) jdcloudDataRequest
                                         url:(NSString*) url
                                      method:(NSString*) method
                           completionHandler:(void(^)(int statusCode, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
     CommonExecutor* excutor = [[CommonExecutor alloc] initWithJDCloudClient:self url:url method:method];
    
    [excutor executeDataAsync:jdcloudDataRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        completionHandler(statusCode,responseData,error);
    }];
} 

@end
